package com.eatme.core.sort;

import com.eatme.core.array.ArrayGenerator;
import com.eatme.core.heap.MaxHeap;

import java.util.Arrays;

public class HeapSort {

    private HeapSort() {

    }

    public static <E extends Comparable<E>> void sort(E [] data) {
        MaxHeap<E> maxHeap = new MaxHeap<>();
        for (E e : data) {
            maxHeap.add(e);
        }

        for (int i = data.length - 1;i >= 0; i--)
            data[i] = maxHeap.extractMax();
    }


    public static void main(String[] args) {
        int n = 10000000;
        System.out.println("RandomArray");
        Integer[] arr = ArrayGenerator.generateRandomArray(n,n);
        Integer[] arr_1 = Arrays.copyOf(arr,arr.length);
        Integer[] arr_2 = Arrays.copyOf(arr,arr.length);
        Integer[] arr_3 = Arrays.copyOf(arr,arr.length);
        Integer[] arr_4 = Arrays.copyOf(arr,arr.length);
        Integer[] arr_5 = Arrays.copyOf(arr,arr.length);
        Integer[] arr_6 = Arrays.copyOf(arr,arr.length);
        Integer[] arr_7 = Arrays.copyOf(arr,arr.length);
        Integer[] arr_8 = Arrays.copyOf(arr,arr.length);
        SortingHelper.sortTest("HeapSort",arr);
        SortingHelper.sortTest("MergeSort",arr_1);
        SortingHelper.sortTest("MergeSortV2",arr_2);
        SortingHelper.sortTest("MergeSortV3",arr_3);
        SortingHelper.sortTest("MergeSortV4",arr_4);
        SortingHelper.sortTest("MergeSortBU",arr_5);
        SortingHelper.sortTest("QuickSortV3",arr_6);
        SortingHelper.sortTest("QuickSortV4",arr_7);
        SortingHelper.sortTest("QuickSortV5",arr_8);


    }
}
